package com.yzc.controller;

import com.yzc.Dto.roleMenu;
import com.yzc.pojo.RoleBean;
import com.yzc.service.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class RoleController {

    final RoleService roleService;
    private static final Marker LOG_MARKER = MarkerFactory.getMarker("LOG");
    /**
     * 获取用户数据
     *
     * @return
     */

    @RequestMapping("/loadRoleList")
    public List<RoleBean> loadRoleList() {
        log.info(LOG_MARKER, "查询角色列表");
        return roleService.loadRoleList();
    }

    /**
     * 修改用户数据
     *
     * @return
     */
    @RequestMapping("/update")
    public Map updateInfo(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "修改角色信息");
        return roleService.updateInfo(roleBean);
    }

    /**
     * 更新用户数据
     *
     * @return
     */
    @RequestMapping("/save")
    public Map save(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "新增角色信息");
        return roleService.save(roleBean);
    }

    /**
     * 删除用户数据
     *
     * @return
     */
    @RequestMapping("/delete")
    public Map deleteInfo(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "删除角色信息");
        return roleService.deleteInfo(roleBean);
    }


    /**
     * 根据id查询角色的菜单
     *
     * @return
     */
    @RequestMapping("/loadRoleMenus")
    public List<roleMenu> loadRoleMenus(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "查询角色对应的菜单信息");
        return roleService.loadRoleMenus(roleBean);
    }

    @RequestMapping("/saveAuthorizationRoleMenu")
    public Map saveAuthorizationRoleMenu(@RequestBody RoleBean roleBean) {
        log.info(LOG_MARKER, "保存角色授权菜单信息");
        return roleService.saveAuthorizationRoleMenu(roleBean);
    }
}
